﻿using DemoQLKhoSX.Library;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;

namespace DemoQLKhoSX.DatabaseAccessLayer
{
    public class ThuKhoDAO
    {
        private DBConnection conn;

        public ThuKhoDAO()
        {
            conn = new DBConnection();
        }

        public DataTable searchByID(string id)
        {
            string query = string.Format("select * from TBL_ThuKho where IDThuKho = @idthukho  or @idthukho = ''");
            SqlParameter[] sqlParameters = new SqlParameter[1];
            sqlParameters[0] = new SqlParameter("@idthukho", SqlDbType.VarChar);
            sqlParameters[0].Value = Convert.ToString(id);
            return conn.executeSelectQuery(query, sqlParameters);
        }
        public bool addthukho(string IDThukho, string Tenthukho, string Chuctrach)
        {
            string query = string.Format("insert into TBL_Thukho values(@IDThukho,@Tenthukho,@Chuctrach)");
            SqlParameter[] sqlparameters = new SqlParameter[3];
            sqlparameters[0] = new SqlParameter("@IDThukho", SqlDbType.VarChar, 10);
            sqlparameters[0].Value = Convert.ToString(IDThukho);
            sqlparameters[1] = new SqlParameter("@Tenthukho", SqlDbType.NVarChar, 50);
            sqlparameters[1].Value = Convert.ToString(Tenthukho);
            sqlparameters[2] = new SqlParameter("@Chuctrach", SqlDbType.NVarChar, 50);
            sqlparameters[2].Value = Convert.ToString(Chuctrach);
            return conn.executeInsertQuery(query, sqlparameters);
        }
        public bool updatethukho(string IDThukho, string Tenthukho, string Chuctrach)
        {
            string query = string.Format("update TBL_Thukho set Tenthukho=@TenThukho,Chuctrach=@Chuctrach where IDThukho=@IDThukho");

            SqlParameter[] sqlparameters = new SqlParameter[3];
            sqlparameters[0] = new SqlParameter("@IDThukho", SqlDbType.VarChar, 10);
            sqlparameters[0].Value = Convert.ToString(IDThukho);
            sqlparameters[1] = new SqlParameter("@Tenthukho", SqlDbType.NVarChar, 50);
            sqlparameters[1].Value = Convert.ToString(Tenthukho);
            sqlparameters[2] = new SqlParameter("@Chuctrach", SqlDbType.NVarChar, 50);
            sqlparameters[2].Value = Convert.ToString(Chuctrach);
            return conn.executeUpdateQuery(query, sqlparameters);
        }
        public bool deletethukho(string IDThukho)
        {
            string query = string.Format("delete from TBL_Thukho where IDThukho=@IDThukho");
            SqlParameter[] sqlparameters = new SqlParameter[1];
            sqlparameters[0] = new SqlParameter("@IDThukho", SqlDbType.VarChar, 10);
            sqlparameters[0].Value = Convert.ToString(IDThukho);
            return conn.executeDeleteQuery(query, sqlparameters);
        }
    }
}
